package com.tlb.dto;

import java.text.SimpleDateFormat;
import javax.persistence.*;
import java.util.*;
import java.io.*;
import java.text.*;

@Entity
public class ThreadList implements Serializable {

    @Transient
    private static SimpleDateFormat LAST_POST_FORMAT = new SimpleDateFormat("MM/dd/yyy");
    @Id
    private int threadId;
    private String title;
    private int postCount;
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastPost;
    private double power;
    private boolean nsfw;
    private boolean spam;
    private boolean tos;

    public int hashCode() {
        return threadId;
    }

    public int getThreadId() {
        return threadId;
    }

    public void setThreadId(int threadId) {
        this.threadId = threadId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getThreadCount() {
        return postCount;
    }

    public void setThreadCount(int threadCount) {
        this.postCount = threadCount;
    }

    public Date getLastPost() {
        return lastPost;
    }

    public String getLastPostString() {
        String retVal = null;
        try {
            retVal = LAST_POST_FORMAT.format(lastPost);
        } catch (Exception e) {
        }
        return retVal == null ? "UNKNOWN" : retVal;
    }

    public void setLastPost(Date lastPost) {
        this.lastPost = lastPost;
    }

    public double getPower() {
        return power;
    }

    public void setPower(double power) {
        this.power = power;
    }

    public boolean getNsfw() {
        return nsfw;
    }

    public void setNsfw(boolean nsfw) {
        this.nsfw = nsfw;
    }

    public boolean getSpam() {
        return spam;
    }

    public void setSpam(boolean spam) {
        this.spam = spam;
    }

    public boolean getTos() {
        return tos;
    }

    public void setTos(boolean tos) {
        this.tos = tos;
    }

    public boolean isHidden(Poster p) {
        if(p == null) //poster not logged in
            return (this.getNsfw() || this.getSpam() || this.getTos());
       
        else if(p.getUserLevelId()!=1 && this.getTos())
            return true;
         
        else if(!p.getNsfw() && this.getNsfw())
                return true;
        else if(!p.getSpam() && this.getSpam())
            return true;
        else
            return false; //admin can always see TOS                    
    }
    
    
    public String getHidenReasonCSSClass(Poster p) {


        if (this.getTos()) {
            return "tosBG";
        } else if (this.getSpam()) {
            return "spamBG";
        } else if (this.getNsfw()) {
            return "nsfwBG";
        } else {
            return "";
        }
    }
}
